/**
 * @author chuzhixin 1204505056@qq.com （不想保留author可删除）
 * @description router全局配置，如有必要可分文件抽离，其中asyncRoutes只有在intelligence模式下才会用到，vip文档中已提供路由的基础图标与小清新图标的配置方案，请仔细阅读
 */

import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layouts'
import EmptyLayout from '@/layouts/EmptyLayout'
import { publicPath, routerMode } from '@/config'

Vue.use(VueRouter)
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
  },
  {
    path: '/register',
    component: () => import('@/views/register/index'),
    hidden: true,
  },
  {
    path: '/401',
    name: '401',
    component: () => import('@/views/401'),
    hidden: true,
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/404'),
    hidden: true,
  },
]

export const asyncRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/personnelManagement/userManagement',
    // children: [
    //   {
    //     path: 'index',
    //     name: 'Index',
    //     component: () => import('@/views/index/index'),
    //     meta: {
    //       title: '首页',
    //       icon: 'home',
    //       affix: true,
    //     },
    //   },
    // ],
  },
  {
    path: '/personnelManagement',
    component: Layout,
    redirect: 'noRedirect',
    name: 'PersonnelManagement',
    meta: { title: '配置', icon: 'users-cog', permissions: ['admin'] },
    children: [
      {
        path: 'userManagement',
        name: 'UserManagement',
        component: () =>
          import('@/views/personnelManagement/userManagement/index'),
        meta: { title: '账号管理', icon: 'street-view' },
      },
    ],
  },
  {
    path: '/report',
    component: Layout,
    redirect: 'noRedirect',
    meta: {
      title: '报表管理',
      open: true,
      icon: 'users-cog',
      permissions: ['admin'],
    },
    children: [
      {
        path: 'jiesuan',
        name: 'jiesuan',
        component: () => import('@/views/report/jiesuan'),
        meta: { title: '结算单', icon: 'comment-dollar' },
      },

      {
        path: 'chicang',
        name: 'chicang',

        component: () => import('@/views/report/chicang'),
        meta: { title: '持仓记录', icon: 'comment-medical' },
      },
      {
        path: 'weituo',
        name: 'weituo',

        component: () => import('@/views/report/weituo'),
        meta: { title: '委托记录', icon: 'comment-dots' },
      },
      {
        path: 'chengjiao',
        name: 'chengjiao',

        component: () => import('@/views/report/chengjiao'),
        meta: { title: '成交记录', icon: 'comment-medical' },
      },
      {
        path: 'churujin',
        name: 'churujin',

        component: () => import('@/views/report/churujin'),
        meta: { title: '出入金记录', icon: 'comments-dollar' },
      },
      {
        path: 'zizhanghu',
        name: 'zizhanghu',

        component: () => import('@/views/report/zizhanghu'),
        meta: { title: '子账户资金', icon: 'comments-dollar' },
      },
    ],
  },

  {
    path: '/baozhenjin',
    component: Layout,
    redirect: 'noRedirect',
    meta: { title: 'baozhenjin', icon: 'users-cog', permissions: ['admin'] },
    children: [
      {
        path: 'index',
        name: 'baozhenjin',
        component: () => import('@/views/baozhenjin/index'),

        meta: { title: '保证金', icon: 'donate' },
      },
    ],
  },

  {
    path: '/fee',
    component: Layout,
    redirect: 'noRedirect',
    meta: { title: 'fee', icon: 'users-cog', permissions: ['admin'] },
    children: [
      {
        path: 'index',
        name: 'fee',
        component: () => import('@/views/fee/index'),

        meta: { title: '手续费', icon: 'file-invoice-dollar' },
      },
    ],
  },

  {
    path: '/exchange',
    component: Layout,
    redirect: 'noRedirect',
    meta: { title: '汇率', icon: 'users-cog', permissions: ['admin'] },
    children: [
      {
        path: 'rate',
        name: 'Rate',
        component: () => import('@/views/exchange/rate'),

        meta: { title: '汇率', icon: 'holly-berry', permissions: ['admin'] },
      },
    ],
  },
  {
    path: '/risk',
    component: Layout,
    redirect: 'noRedirect',
    meta: { title: '风控', icon: 'users-cog', permissions: ['admin'] },
    children: [
      {
        path: 'index',
        name: 'Risk',
        component: () => import('@/views/risk/index'),

        meta: { title: '风控', icon: 'jedi', permissions: ['admin'] },
      },
    ],
  },

  {
    path: '/condition',
    component: Layout,
    redirect: 'noRedirect',
    meta: { title: '条件单', icon: 'users-cog', permissions: ['admin'] },
    children: [
      {
        path: 'index',
        name: 'Condition',
        component: () => import('@/views/condition/index'),

        meta: { title: '条件单', icon: 'infinity', permissions: ['admin'] },
      },
    ],
  },

  // {
  //   path: '/system',
  //   component: Layout,
  //   redirect: 'noRedirect',
  //   meta: { title: '系统日志', icon: 'users-cog', permissions: ['admin'] },
  //   children: [
  //     {
  //       path: 'log',
  //       name: 'Log',
  //       component: () => import('@/views/system/log'),
  //       meta: { title: '系统日志', icon: '', permissions: ['admin'] },
  //     },
  //   ],
  // },

  {
    path: '/error',
    component: EmptyLayout,
    redirect: 'noRedirect',
    name: 'Error',
    meta: { title: '错误页', icon: 'bug' },
    hidden: true,
    children: [
      {
        path: '401',
        name: 'Error401',
        component: () => import('@/views/401'),
        meta: { title: '401', icon: 'bug' },
      },
      {
        path: '404',
        name: 'Error404',
        component: () => import('@/views/404'),
        meta: { title: '404', icon: 'bug' },
      },
    ],
  },
  {
    path: '*',
    redirect: '/404',
    hidden: true,
  },
]

const router = new VueRouter({
  base: publicPath,
  mode: routerMode,
  scrollBehavior: () => ({
    y: 0,
  }),
  routes: constantRoutes,
})
//注释的地方是允许路由重复点击，如果你觉得框架路由跳转规范太过严格可选择放开
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch((err) => err)
}

export function resetRouter() {
  router.matcher = new VueRouter({
    base: publicPath,
    mode: routerMode,
    scrollBehavior: () => ({
      y: 0,
    }),
    routes: constantRoutes,
  }).matcher
}

export default router
